﻿using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using util;

namespace WebApplication1.StudentUser
{
    public partial class Student : System.Web.UI.MasterPage
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            Panel1.Visible = false;
            Panel2.Visible = false;
            String roleName = (String)Application["rolename"];
            if (roleName != "学生")
            {
                Response.Write("<script>alert('没有权限查看此页面')</script>");
                Server.Transfer("\\login\\login.aspx");
            }
            user_name.Text =  Application["name"].ToString();
        }

        protected void TreeView1_SelectedNodeChanged(System.Object sender, System.EventArgs e)
        {

        }

        protected void Image2_Click(object sender, ImageClickEventArgs e)
        {
            bool a = Panel1.Visible;
            a = !a;
            Panel1.Visible = a;
        }

        protected void LinkButton1_Click(object sender, EventArgs e)
        {
            Server.Transfer("\\login\\login.aspx");
        }

        protected void LinkButton2_Click(object sender, EventArgs e)
        {
            Panel2.Visible = true;
        }

        protected void okAdd_Click(object sender, EventArgs e)
        {
            String oldpass = oldpassword.Text;
            String newpass = newpassword.Text;
            String epass = epasssword.Text;
            int id = (int)Application["userId"];
            String username = (String)Application["username"];
            String sql2 = "SELECT * FROM `user` WHERE username = '" + username + "'and `password` ='" + username + "'";
            DataTable table = MySqlHelper.GetDataTable(sql2);
            if (table.Rows.Count == 0)
            {
                Response.Write("<script>alert('密码错误，请重新输入！')</script>");
            }
            else
            {
                String sql = "UPDATE `user` set `password` = '" + newpass + "' WHERE id = " + id;
                DataTable Adt = MySqlHelper.GetDataTable(sql);
                Response.Write("<script>alert('修改成功，请重新登入！')</script>");
                Server.Transfer("\\login\\login.aspx");
            }
        }

        protected void escAdd_Click(object sender, EventArgs e)
        {
            this.Panel2.Visible = false;
        }
    }
}
